#ifndef FSFUNCTIONS_H_
#define FSFUNCTIONS_H_
void format (char *par) {
	char  label[12];
  char *drive;

  drive = NULL;

  if (par) {
    if (par[1] == ':') {
      drive = par;
      par += 2;
    }
    else if (par[2] == ':')	{
      drive = par;
      par += 3;
    }
  }
	
  /* Format the drive */
  if (fformat (drive, par) == fsOK) {
		if (fvol (drive, label, NULL) == 0)	{
			if (label[0] != '\0')	{
				//printf ("Volume label is \"%s\"\n", label);
			}
    }
    else {
			// printf ("Formatting failed.\n");
    }
  }
}

void init_filesystem (void) {
	fsStatus stat;
  stat = finit("M0:");
  if (stat == fsOK) {
		stat = fmount("M0:");
		if (stat == fsOK) {
    }
    else if (stat == fsNoFileSystem) {
      format("M0:");
    }
    else {
    }
  }
  else {
  }
}

void uninit_filesystem(void){
	fsStatus stat;
  stat = funmount("M0:");
  if (stat == fsOK) {
		stat = funinit("M0:");
		if (stat == fsOK) {
		}
	}
}

void create_file (char *fname) {
  FILE *f;
  int i, cnt = 1000;

  f = fopen (fname, "w"); /* open a file for writing */
  if (f == NULL) {
    /* error when trying to open file */
    return;
  } 
  for (i = 0; i < cnt; i++)  {
    fprintf (f, "This is line # %d in file %s\n", i, fname);
    if (!(i & 0x3FF)) printf("."); 
		fflush (stdout);
  }
  fclose (f);  /* close the output file  */
}

void delete_file (char *fname) {
  if (fname == NULL) {
    return;
  }
  fdelete (fname);		
}
#endif

